package scalaLearning.part1.works

class Person   //父类

case class Student(name:String) extends Person

case class Teacher(name:String,age:Int) extends Person

case class NoBody() extends Person

object Test3 {
  def main(args: Array[String]): Unit = {
    val p:Person = new Student("tom")
    val s:Person = new Teacher("tom",20)
    println(s)
    //通过多态的父类引用，匹配子类对象
    s match {
      case Student(name) => println("Student")
      case Teacher(name,age) => println("Teacher")
      case NoBody() => println("NoBody")
    }
  }
}





